"""
- json.dumps
    - ensure_ascii=False 显示中文
    - indent=4 缩进4个空格
"""
import json
items = [
    {'name': "张三", 'age': 19, "score": 80},
    {'name': "李四", 'age': 20, "score": 81},
    {'name': "王五", 'age': 21, "score": 82},
]
# 编码
s = json.dumps(items, ensure_ascii=False, indent=4)
print('类型：%s, 值：%s' % (type(s), s), end='\n')

# 解码
items = json.loads(s)
print('类型：%s, 值：%s' % (type(items), items), end='\n')

# 编码到文件
with open('data/iii.json', 'w', encoding='utf-8') as f:
    json.dump(items, f, ensure_ascii=False, indent=4)

# 解码到程序
with open('data/iii.json', 'r', encoding='utf-8') as f:
    print('list = ', json.load(f), end='\n')
